home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CDICTION / CTESTDIC.C < prev    next >
Text File  |  1990-01-12  |  1KB  |  54 lines

  1.  
  2. #include "CTestDict.h"
  3. #include "CPascalString.h"
  4. #include "TBUtilities.h"
  5.  
  6. /* map and compare procs for dictionary */
  7.  
  8. uInt32 MapKey( void *key);    /* map string to unsigned long */
  9. Boolean CompareKeys( void *key1, void *key2);    /* compare two keys */
  10.  
  11. /********************************************************************/
  12. Boolean CTestDict::ITestDict( void )
  13. {
  14.     CDictionary::IDictionary( sizeof(Str20), MapKey, CompareKeys, 0);
  15.  
  16. }    /* CTestDict::ITestDict */
  17. /********************************************************************/
  18.  
  19. /* map and compare procs for dictionary */
  20.  
  21. uInt32 MapKey( void *key)    /* map string to unsigned long */
  22. {
  23.     Str20    copy;
  24.     register unsigned char *s;
  25.     register uInt32 sum = 1;
  26.     register Int16    i, triplets;
  27.     register unsigned short ch;
  28.     Int16    length;
  29.     
  30.     pStrCopy( key, copy);
  31.     UprString( copy, FALSE);
  32.     s = copy;
  33.     length = *s++;
  34.     triplets = length / 3;
  35.     for (i = 0; i < triplets; i++)
  36.     {
  37.         sum *= *s++;
  38.         ch = *s++;
  39.         sum *= ch << 1;
  40.         ch = *s++;
  41.         sum *= ch << 2;
  42.     }
  43.     for (i = triplets * 3; i < length; i++)
  44.         sum *= *s++;
  45.         
  46.     sum >>= 8;
  47.                 
  48.     return sum;
  49.  
  50. }
  51. Boolean CompareKeys( void *key1, void *key2)    /* compare two keys */
  52. {
  53.     return EqualString( key1, key2, FALSE, FALSE);
  54. }